/**
 * 
 */
package com.yidu.menuProject.action;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

import javax.annotation.Resource;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpSession;

import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import com.yidu.menuProject.action.vo.EhyManagerVo;
import com.yidu.menuProject.action.vo.FindFood;
import com.yidu.menuProject.action.vo.FoodAndCart;
import com.yidu.menuProject.action.vo.UserIndent;
import com.yidu.menuProject.common.Page;
import com.yidu.menuProject.commont.Tools;
import com.yidu.menuProject.model.IndentModel;
import com.yidu.menuProject.model.TuserModel;
import com.yidu.menuProject.service.IndentService;
import com.yidu.menuProject.service.KeepService;
/**
 * 类的描述--订单Action
 * @author sylval
 * @date 2018年7月13日 上午10:34:09
 * @version 1.0
 */
@Controller
@RequestMapping("/indentAction")
public class IndentAction {
	@Resource
	IndentService inService;
	@Resource
	KeepService keService;
	/**
	 * 显示所有
	 * @return
	 */
	@ResponseBody
	@RequestMapping("/showAjax")
	public Map<String,Object> showAjax(HttpSession session,int page,int limit){
		EhyManagerVo ehymanger = (EhyManagerVo) session.getAttribute("user");
		Page vo = new Page();
		vo.setNowpage(page-1);
		vo.setRows(limit);
		System.out.println(page+"------======="+limit);
		List<UserIndent> userList = inService.findIndent(vo,ehymanger.getMealId());
		Map<String,Object> map=new HashMap<>();
		map.put("code", 0);
		map.put("msg", "1");
		map.put("count", inService.findTotalRows());
		map.put("data", userList);
		return map;
	}
	/**
	 * 查询页面的方法
	 */
	@ResponseBody
	@RequestMapping("/findPage")
	public Page findPage(){
		int total=inService.findTotalRows();
		Page page=new Page();
		page.setTotalRows(total);//总行数
		return page;
	}
	/**
	 * 查询订单的方法
	 */
	@ResponseBody
	@RequestMapping("/findIndent")
	public List<IndentModel> findIndent(HttpSession session){
		TuserModel tuserModel = (TuserModel)session.getAttribute("tuserModel");
		
		List<IndentModel> mo=inService.selectIndent(tuserModel.getUserId());
		return mo;
	}
	
	/**
	 * 查询食物的方法
	 */
	@ResponseBody
	@RequestMapping("/findFood")
	public List<FindFood> findFood(String indId){
		List<FindFood> mo=inService.findFood(indId);
		return mo;
	}
	/**
	 * 根据购物车的id查询信息
	 */
	@ResponseBody
	@RequestMapping("/findMessageByKeepId")
	public 	List<FoodAndCart> findMessageByKeepId(HttpSession session){
		String cartId = (String) session.getAttribute("gucSJ");
		List<FoodAndCart> list=(List<FoodAndCart>) keService.FindMessage(cartId);
		return list;
	}
	/**
	 * 增加订单的方法
	 * @param record
	 * @return
	 */
	@RequestMapping("/addIndent")
	@ResponseBody
	public void addIndent(IndentModel record,HttpServletRequest request,String foodId,String foodNum){
		record.setIndId(Tools.getRandomString(20));
		TuserModel tuserModel =(TuserModel) request.getSession().getAttribute("tuserModel");
		record.setUserId(tuserModel.getUserId());
		inService.insertSelective(record,foodId,foodNum);
	}
}
